<?php
/*
 * CopyRight © 2012
 *
  -------------------------------------------------------------
 * File:     FormCheck.php
 * Type:     api
 * Name:     FormCheck
 * Version:  1.0
 * Date:
 * Directory: include/util/FormCheck.php
 * Author:   HuangTingTing
 * Purpose: 表单验证类
  -------------------------------------------------------------
 */
class FormCheck
{

  public static function SetFormKey($paramers=null)
  {
    $key = "";
    $str = "";
    while ($value = key($paramers)) {
      $key .= $value . "/";
      $str .= $paramers[$value] . "_";
      next($paramers);
    }

    srand((double) microtime() * 1000000);
    $rand = rand(1000, 10000);
    $str .= $rand;


    $_SESSION["md5"]["rand"] = $rand;
    $_SESSION["md5"]["md5"] = md5($str);
    $_SESSION["md5"]["key"] = $key;
  }

  public static function Fcheck($paramers)
  {
    $key = $_SESSION["md5"]["key"];
    $rand = $_SESSION["md5"]["rand"];
    $str = $_SESSION["md5"]["md5"];
    $tmp = explode("/", $key);
    $str_ = "";
    
    for($i=0; $i<count($tmp)-1; $i++)
    {
      $str_ .= $paramers[$tmp[$i]] . "_";
    }
    $str_ .= $rand;

    if(md5($str_) == $str)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

}

?>